{{--
/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/3/9 15:02
 * Desc:
 */--}}
@extends("layout.admin")

@section("title")
    角色列表
@endsection

@section("content")
    {{--修改样式--}}
    <link href="{{asset('css/table.css')}}" rel="stylesheet"/>
    {{--列表--}}
    <div class="layui-card-body ">
        {{--搜索--}}
        @include("admin.role.search")
    </div>

    <div class="layui-card-body ">
        <script type="text/html" id="toolbar">
            @can("admin.role.create")
            <div class="layui-show-xs-block layui-input-inline">
                <a class="layui-btn layui-btn-sm"
                   onclick="admin.openLayerForm('{{ route("admin.role.create") }}', '添加角色', 'POST', '500px', '280px')"><i
                        class="layui-icon"></i>添加</a>
            </div>
            @elsecan("system.role.create")
            <div class="layui-show-xs-block layui-input-inline">
                <a class="layui-btn layui-btn-sm"
                   onclick="admin.openLayerForm('{{ route("system.role.create") }}', '添加角色', 'POST', '500px', '280px')"><i
                        class="layui-icon"></i>添加</a>
            </div>
            @endcan
        </script>
        <table class="layui-table" lay-filter="table-button"
               lay-data="{toolbar: '#toolbar',defaultToolbar:['filter'], limit: {{$error==0?$roles['per_page']:12}} }">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80, fixed: 'left', unresize: true, sort: true}">编号</th>
                <th lay-data="{field:'name'}">名称</th>
                <th lay-data="{field:'is_system',hide:true}">角色类型</th>
                {{--<th lay-data="{field:'site_id'}">站点</th>
                <th lay-data="{field:'guard_name'}">守卫</th>--}}
                <th lay-data="{field:'created_at'}">创建时间</th>
                <th lay-data="{field:'updated_at'}">更新时间</th>
                <th lay-data="{field:'op',fixed: 'right', width:100, align:'center',toolbar: '#buttons'}">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($roles["data"] as $role)
                <tr>
                    <td>{{ $role['id'] }}</td>
                    <td>{{ $role['name'] }}</td>
                    <td>{{ $role['is_system']==1?'系统':'自建' }}</td>
                    {{--<td>{{ $role['site']['name'] }}</td>
                    <td>{{ $role['guard_name'] }}</td>--}}
                    <td>{{ $role['created_at'] }}</td>
                    <td>{{ $role['updated_at'] }}</td>
                    <td data-field="controller">
                        <script type="text/html" id="buttons">
                            <a class="layui-btn layui-btn-xs" lay-event="more">管理 <i
                                    class="layui-icon layui-icon-down"></i></a>
                        </script>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        @include("layout.page")
    </div>
@endsection

@section('script')
    <script>
        var idx = -1;
        const error = {{$error}};
        layui.use(['dropdown','table', 'layer'], function () {
            var dropdown = layui.dropdown,table=layui.table;

            //操作按钮组事件
            table.on('tool(table-button)', function (obj) {
                var that = this
                    , res = obj.data;
                //更多下拉菜单
                let buttons = [@if(_can(session("guard").".role.show")){title: '查看详情', id: 'show',type:'link',link:"{{ route_uri(session("guard").".role.show")}}",params:{role: res.id}},@endif]
                if(guard == "system" || res.is_system!="系统"){
                    let temp =[
                    @if(_can(session("guard").".role.edit")){title: '修改角色', id: 'edit',type:'openLayerForm',link:"{{ route_uri(session("guard").".role.edit")}}",params:{id:res.id},set:{title:"修改角色",method:"POST",width:"500px",height:"260px",repush:0,dome:"#edit-form"}}, @endif
                    @if(_can(session("guard").".role.per_form")){title: '分配权限', id: 'assign',type:'link',link:"{{ route_uri(session("guard").".role.per_form") }}",params:{id:res.id}}, @endif
                    @if(_can(session("guard").".role.destroy")){title: '删除角色', id: 'del',type:'tableDataDelete',link:"{{ route_uri(session("guard").".role.destroy") }}",params:{id:res.id},set:{dome:this,title:"是否删除当前角色"}} @endif
                    ]
                    buttons.push.apply(buttons,temp)
                }

                dropdown.render(tableButtonGroup(that, buttons))
            });

            //分页显示
            @if($error==0)
            admin.paginate("{{ $roles['total'] }}", "{{ $roles['current_page'] }}", "{{ $roles['per_page'] }}");
            @endif
        });
    </script>
@endsection
